package lzw;

import dcc.Rle;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class Main {
        public static void main(String[] args) throws IOException {
                try {
                    int soicouldcommit = 0;
//                    LZW lzw = new LZW();
////                    Rle rle = new Rle();
//                    String filename = "D:/test/bark.bmp";
//                    FileInputStream in = new FileInputStream(filename);
//                    FileOutputStream out = new FileOutputStream(filename+".lzw");
//                    lzw.compress(in, out);
//                    in = new FileInputStream(filename+".lzw");
//                    out = new FileOutputStream(filename+".lzw.bmp");
//                    lzw.decompress(in, out);
//                    calculate(filename,filename+".lzw");
//                    
//                    filename = "D:/test/document.bmp";
//                    in = new FileInputStream(filename);
//                    out = new FileOutputStream(filename+".lzw");
//                    lzw.compress(in, out);
//                    in = new FileInputStream(filename+".lzw");
//                    out = new FileOutputStream(filename+".lzw.bmp");
//                    lzw.decompress(in, out);
//                    calculate(filename,filename+".lzw");
//                    
//                    
//                    filename = "D:/test/grass.bmp";
//                    in = new FileInputStream(filename);
//                    out = new FileOutputStream(filename+".lzw");
//                    lzw.compress(in, out);
//                    in = new FileInputStream(filename+".lzw");
//                    out = new FileOutputStream(filename+".lzw.bmp");
//                    lzw.decompress(in, out);
//                    calculate(filename,filename+".lzw");
////                    
//                    filename = "D:/test/house.bmp";
//                    in = new FileInputStream(filename);
//                    out = new FileOutputStream(filename+".lzw");
//                    lzw.compress(in, out);
//                    in = new FileInputStream(filename+".lzw");
//                    out = new FileOutputStream(filename+".lzw.bmp");
//                    lzw.decompress(in, out);
//                    calculate(filename,filename+".lzw");
////                    
//                    filename = "D:/test/Lena.bmp";
//                    in = new FileInputStream(filename);
//                    out = new FileOutputStream(filename+".lzw");
//                    lzw.compress(in, out);
//                    in = new FileInputStream(filename+".lzw");
//                    out = new FileOutputStream(filename+".lzw.bmp");
//                    lzw.decompress(in, out);
//                    calculate(filename,filename+".lzw");
//                    
//                    filename = "D:/test/peppers.bmp";
//                    in = new FileInputStream(filename);
//                    out = new FileOutputStream(filename+".lzw");
//                    lzw.compress(in, out);
//                    in = new FileInputStream(filename+".lzw");
//                    out = new FileOutputStream(filename+".lzw.bmp");
//                    lzw.decompress(in, out);
//                    calculate(filename,filename+".lzw");
//                    
//                    filename = "D:/test/sand.bmp";
//                    in = new FileInputStream(filename);
//                    out = new FileOutputStream(filename+".lzw");
//                    lzw.compress(in, out);
//                    in = new FileInputStream(filename+".lzw");
//                    out = new FileOutputStream(filename+".lzw.bmp");
//                    lzw.decompress(in, out);
//                    calculate(filename,filename+".lzw");
//                    
//                    filename = "D:/test/WashingtonDC.bmp";
//                    in = new FileInputStream(filename);
//                    out = new FileOutputStream(filename+".lzw");
//                    lzw.compress(in, out);
//                    in = new FileInputStream(filename+".lzw");
//                    out = new FileOutputStream(filename+".lzw.bmp");
//                    lzw.decompress(in, out);
//                    calculate(filename,filename+".lzw");
//                    
//                    filename = "D:/test/file1.bin";
//                    in = new FileInputStream(filename);
//                    out = new FileOutputStream(filename+".lzw");
//                    lzw.compress(in, out);
//                    in = new FileInputStream(filename+".lzw");
//                    out = new FileOutputStream(filename+".lzw.bin");
//                    lzw.decompress(in, out);
//                    calculate(filename,filename+".lzw");
//                    
//                    filename = "D:/test/file2.bin";
//                    in = new FileInputStream(filename);
//                    out = new FileOutputStream(filename+".lzw");
//                    lzw.compress(in, out);
//                    in = new FileInputStream(filename+".lzw");
//                    out = new FileOutputStream(filename+".lzw.bin");
//                    lzw.decompress(in, out);
//                    calculate(filename,filename+".lzw");
//                    
//                    filename = "D:/test/text1.txt";
//                    in = new FileInputStream(filename);
//                    out = new FileOutputStream(filename+".lzw");
//                    lzw.compress(in, out);
//                    in = new FileInputStream(filename+".lzw");
//                    out = new FileOutputStream(filename+".lzw.txt");
//                    lzw.decompress(in, out);
//                    calculate(filename,filename+".lzw");
//                    
//                    filename = "D:/test/text2.txt";
//                    in = new FileInputStream(filename);
//                    out = new FileOutputStream(filename+".lzw");
//                    lzw.compress(in, out);
//                    in = new FileInputStream(filename+".lzw");
//                    out = new FileOutputStream(filename+".lzw.txt");
//                    lzw.decompress(in, out);
//                    calculate(filename,filename+".lzw");
                } catch (Exception e) {
                    System.out.println("error: "+e.getMessage());
                }
        }
        
        public static void calculate(String a, String b){
        File in = new File(a);
        File out = new File(b);
//        System.out.println("in: "+in.length()+" "+out.length());
        double compressionRate = (double)(in.length() - out.length()) / (double)in.length();
        System.out.println("Compression rate: "+compressionRate);
        }
}